package com.clz.appdesign.myapp.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * @author chenliangzhi
 * @date 2018/5/24
 * @describe
 */

public class BitMapCanvasView extends View {
    private Bitmap mBitmap;
    private Paint mPaint;
    private Canvas mBitMapCanvas;
    public BitMapCanvasView(Context context) {
        super(context);
    }

    public BitMapCanvasView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        mPaint=new Paint();
        mPaint.setColor(Color.RED);
        mBitmap=Bitmap.createBitmap(800,500,Bitmap.Config.ARGB_8888);
        //用bitmap构建canvas
        mBitMapCanvas=new Canvas(mBitmap);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        mPaint.setTextSize(100);
        mBitMapCanvas.drawText("再见只是陌生人",0,100,mPaint);
        canvas.drawBitmap(mBitmap,0,0,mPaint);
    }

    public BitMapCanvasView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

}
